<template>
  <div class="app-wrapper">
    <headerTitle :titleList="titleList" />
    <div class="app-container">
      <div class="containerMain">
        <div >
            <div style="display: flex;">
              <div style="display: flex;flex-direction: column;">
                <img style="width: 260px" :src="imageUrl" />
                <br>
                <span style="margin-left:120px">{{imageName}}</span>
              </div>
            </div>
          <br><br><br>
              <el-button style="margin-left: 30px; height: 38px" @click="cancel()"
            >返回</el-button
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import Pagination from "@/components/Pagination/index";
import HeaderTitle from "@/components/Headertitle/index";
import { fetchAgentList } from "@/api/systemapi/agent";
import {
  fetchList,
  fetchDetailExport,
  fetchVideoList,
  fetchPhotoList,
  fetchDel
} from "@/api/systemapi/video";
import { fetchAll } from "@/api/systemapi/skill";
import { pageParams } from "@/settings";

export default {
  components: {
    Pagination,
    HeaderTitle,
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: "启用",
        2: "禁用",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      titleList: [{ title: "截图" }],
      rows: "10",
      page: "1",
      imageUrl:"",
      imageName:"",
      //视频用到的参数
      meetingId: "",
      customerVideoNum: "",
      agentId: "",
      customerJoinTime: "",
      customerLeaveTime: "",
      recordFile: "",
      sessionId: "",
      list: [],
      skillList: [],
      timeValue: [],
      listLoading: true,
      skillGroupList: [],
      searchform: {
        recordStartTimeLeft: "",
        recordStartTimeRight: "",
        meetingId: "",
        recordFileId: "",
        sessionId: "",
      },
      // 分页
      pagination: pageParams,
    };
  },
  watch: {
    // 分页
    "pagination.currentPage": function () {
      //this.searchform.page = this.pagination.currentPage;
      this.fetchData();
    },
    "pagination.pageSize": function () {
      this.searchform.rows = this.pagination.pageSize;
      //this.searchform.page = 1;
      this.fetchData();
    },
  },
  mounted() {
    // this.meetingId = this.$route.query.meetingId;
    // this.sessionId = this.$route.query.sessionId;
    //调用照片接口
    // this.fetchData();
    //调用照片接口
    // this.fetchData();
    this.imageUrl=this.$route.query.url
    this.imageName=this.$route.query.name
  },
  methods: {
    exportUser() {
      downloadUserInfo({
        exportType: 1,
        ...this.searchform,
      }).then((res) => {
        let blob = new Blob([res.data], {
          type: "application/vnd.ms-excel",
        });
        let str = res.headers["content-disposition"].split(";")[1];
        // console.log(str,"str1111")
        if (str.indexOf("=") != -1) {
          var filename = decodeURI(str.slice(9));
        } else {
          var filename = decodeURI(str);
        }
        var downloadElement = document.createElement("a");
        var href = window.URL.createObjectURL(blob); //创建下载的链接
        downloadElement.href = href;
        downloadElement.download = filename; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放掉blob对象
      });
    },
    exportDemo() {
      downloadUserInfo({ exportType: 2 }).then((res) => {
        let blob = new Blob([res.data], {
          type: "application/vnd.ms-excel",
        });
        let str = res.headers["content-disposition"].split(";")[1];
        // console.log(str,"str1111")
        if (str.indexOf("=") != -1) {
          var filename = decodeURI(str.slice(9));
        } else {
          var filename = decodeURI(str);
        }
        var downloadElement = document.createElement("a");
        var href = window.URL.createObjectURL(blob); //创建下载的链接
        downloadElement.href = href;
        downloadElement.download = filename; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放掉blob对象
      });
    },
    //表头背景颜色修改
    headerStyle({ row, column, rowIndex, columnIndex }) {
      if (rowIndex == 0) {
        return "background:#F5F6FB;color:#666";
      }
    },
    getOrganList() {
      fetchOrganList().then((res) => {
        this.treeData = res.data;
      });
    },
    // 账号权限下拉
    getAccount() {
      fetchAccount().then((res) => {
        this.accountList = res.rows;
      });
    },
    // 点击树形节点 ，过滤列表坐席
    filterDepart(data) {
      let organId =
        this.searchform.organId.length > 0
          ? this.searchform.organId[this.searchform.organId.length - 1]
          : "";
      fetchAgentList({
        organTreeId: data.id,
        entNum: this.entNum,
        username: this.searchform.username,
        roleId: this.searchform.roleId,
        organId: organId,
        //rows: this.searchform.rows,
        //page: this.searchform.page,
      }).then((response) => {
        if (response.code == 0) {
          this.list = response.data.rows;
          this.pagination.total = response.data.records;
        } else {
          this.$message({
            type: "error",
            message: response.msg,
          });
        }
      });
    },
    // 重置搜索，刷新列表
    reset() {
      (this.searchform = {
        recordStartTimeLeft: "",
        recordStartTimeRight: "",
        meetingId: "",
        recordFileId: "",
        sessionId: "",
        //rows: "10",
        //page: "1",
      }),
        (this.timeValue = []);
      this.fetchData();
    },
    getSkillList() {
      fetchAll().then((response) => {
        if (response.code == 0) {
          this.skillList = response.data.list;
        }
      });
    },

    cancel(){
        this.$router.back();//返回上一步
    },

    //跳转进详情页
    viewDetail(row) {},

    //播放视频
    playVideo(row) {},

    downloadVideo(row) {
      window.open(row);
    },

    exportDetail() {
      if (this.timeValue != null && this.timeValue.length > 0) {
        this.searchform.recordStartTimeLeft = moment(this.timeValue[0]).format(
          "YYYY-MM-DD HH:mm:ss"
        );
        this.searchform.recordStartTimeRight = moment(this.timeValue[1]).format(
          "YYYY-MM-DD HH:mm:ss"
        );
      } else {
        //不选时间默认展示今天得
        this.searchform.recordStartTimeLeft = "";
        this.searchform.recordStartTimeRight = "";
      }

      fetchDetailExport({ ...this.searchform }).then((res) => {
        console.log(res);
        let blob = new Blob([res.data], {
          type: "application/vnd.ms-excel",
        });
        let str = res.headers["content-disposition"].split(";")[1];
        // console.log(str,"str1111")
        if (str.indexOf("=") != -1) {
          var filename = decodeURI(str.slice(9));
        } else {
          var filename = decodeURI(str);
        }
        var downloadElement = document.createElement("a");
        var href = window.URL.createObjectURL(blob); //创建下载的链接
        downloadElement.href = href;
        downloadElement.download = filename; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放掉blob对象
      });
    },

    fetchData() {
      fetchPhotoList({
        meetingId: this.meetingId,
        sessionId: this.sessionId,
      }).then((response) => {
        if (response.code == 0) {
          this.list = response.data;
          this.pagination.total = response.data.records;
          console.log(response.data.list);
          console.log(this.list, "this.list");
        } else {
          this.$message({
            type: "error",
            message: response.msg,
          });
        }
      });
    },
    fetchDetailData(id) {
      fetchDetail({ id: id }).then((response) => {
        if (response.code == 0) {
          this.list = response.data;
          this.pagination.total = response.data.records;
          this.$router.push({ path: "/" });
        } else {
          this.$message({
            type: "error",
            message: response.msg,
          });
        }
      });
    },
    // 删除
    del(sessionId,ids) {
      this.$confirm("是否确定删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        fetchDel({sessionId:sessionId,ids:ids}).then((response) => {
          if (response.code === 0) {
            this.fetchData();
            this.$message({
              message: "删除成功",
              type: "success",
            });
          } else {
            this.$message({
              message: response.msg,
              type: "error",
            });
          }
        });
      });
    },
    recover(data) {
      fetchRecover({ id: data.id, userType: "3" }).then((response) => {
        if (response.code === 0) {
          this.fetchData();
          this.$message({
            message: "恢复成功",
            type: "success",
          });
        } else {
          this.$message({
            message: response.msg,
            type: "error",
          });
        }
      });
    },
    resetPas(data) {
      this.$confirm("是否确定重置密码?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          fetchSetPsd({ id: data.id }).then((response) => {
            if (response.code === 0) {
              this.$message({
                message: "重置成功",
                type: "success",
              });
              this.fetchData();
            } else {
              this.$message({
                message: response.msg,
                type: "error",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消重置",
          });
        });
    },
    // 新增
    add(data) {
      this.$router.push({
        path: "/system/agent/detail",
        query: { type: 3 },
      });
    },
    editBtn(data) {
      this.$router.push({
        path: "/system/agent/detail",
        query: { type: "2", id: data.id },
      });
    },
    viewFn(data) {
      this.$router.push({
        path: "/system/agent/detail",
        query: { type: "1", id: data.id },
      });
    },
    handelExport() {
      this.dialogVisible = true;
    },
    // 批量导入文件
    httpRequestExport(param) {
      let fileObj = param.file; // 相当于input里取得的files
      let fd = new FormData(); // FormData 对象
      fd.append("file", fileObj); // 文件对象
      fetchExport(fd).then((res) => {
        if (res.code == 0) {
          this.dialogVisible = false;
          this.fetchData();
        } else {
          this.$message({
            type: "error",
            message: res.msg,
          });
        }
      });
    },
    submitUpload() {
      this.$refs.uploadBatch.submit();
    },
    // resetFileds() {
    //   // 重置校验
    //   if (this.$refs["ruleForm"]) {
    //     this.$refs["ruleForm"].resetFields();
    //   }
    // }
  },
};
</script>
<style lang="scss">
.tree-con {
  .el-tree-node__content {
    margin-bottom: 20px;
  }
}
</style>
<style lang="scss" scoped>
.containerMain {
  width: 100%;
  .search-item {
    flex: 1;
    padding: 20px 10px;
    font-size: 14px;
    color: #666;
    display: flex;
    justify-content: space-between;
    .item-list {
      display: flex;
      flex-wrap: wrap;
    }
    .item-con {
      display: flex;
      margin-right: 30px;
      margin-top: 20px;

      span {
        display: inline-block;
        line-height: 28px;
        margin-right: 10px;
      }
    }
    .item {
      width: 180px;
    }
  }
  .container {
    display: flex;
    flex-direction: row;
    .div-tree {
      width: 250px;
    }
    .div-table {
      flex: 1;
      width: 100%;
      overflow: hidden;
      .el-table {
        height: 100%;
        width: 100%;
        overflow: auto;
      }
    }
    .el-row {
      height: 300px;
      .el-col {
        height: 100%;
        .div-tree {
          height: 90%;
          .el-tree {
            height: 100%;
            overflow-y: auto;
          }
        }
      }
    }
  }
  .item-btn {
    margin-top: 20px;
    flex: 0 0 140px;
  }
}
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
</style>
